#!/bin/bash
num=`expr $# % 2`			#用于判断输入参数个数是否为偶数
target=`expr $1`			#用于取目标文件名，保证后续表格始终与目标文件执行py文件
ws=`pwd`
if ! type python3 >/dev/null 2>&1; then
	yum -y install gcc
	yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
#	cd /usr/local/
#	wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
#	mkdir /usr/local/Python-3.7.0
	tar -zxvf Python-3.7.0.tgz -C /usr/local
	mkdir /usr/local/python3
#	cd Python-3.7.0
	cd /usr/local/Python-3.7.0/
	./configure --prefix=/usr/local/python3
	make && make install
	cd $ws
#	PATH=$PATH:/usr/local/python3/bin/
	python3 -m pip install xlrd
else
	python3 -m pip install xlrd
fi

if [ $# -lt 3 ];then 
	echo "Usage:bash hebing.sh target.xls ratio1 source1.xls ratio2 source2.xls ..."
	exit
elif [ "$num" -eq 1 ];then
	shift
	until [ $# -eq 0 ]
		do
		python3 main.py -t $target -s $1 -k $2
#		echo "$target $1 $2"	#将echo这一行改为python3 py文件名 $target $1 $2 						#如果不行就需要修改py的环境变量，在安装的if条件语句中配置
		shift 2
	done
else
	echo "Usage:bash hebing.sh target.xls ratio1 source1.xls ratio2 source2.xls ..."
	exit
fi

